package com.ruoyi.report.controller;

import cn.hutool.http.HttpResponse;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.report.domain.MandatoryReport;
import com.ruoyi.report.service.IMandatoryReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;


/**
 * 【请填写功能名称】Controller
 *
 * @author huanshihao
 * @date 2025-02-10
 */

@RestController
@RequestMapping("/project/report")
public class MandatoryReportController extends BaseController {
    private String prefix = "project/report";

    @Autowired
    private IMandatoryReportService mandatoryReportService;

    @GetMapping()
    public String report() {
        return prefix + "/report";
    }

    /**
     * 查询【请填写功能名称】列表
     */
    @GetMapping("/list")
    public TableDataInfo list(MandatoryReport mandatoryReport) {
        startPage();
        List<MandatoryReport> list = mandatoryReportService.selectMandatoryReportList(mandatoryReport);
        return getDataTable(list);
    }

    /**
     * 查询【请填写功能名称】列表
     */
    @GetMapping("/listPc")
    public TableDataInfo list1(MandatoryReport mandatoryReport) {
        startPage();
        List<MandatoryReport> list = mandatoryReportService.selectMandatoryReportList1(mandatoryReport);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @PostMapping("/export")
    public AjaxResult export(@RequestBody MandatoryReport mandatoryReport) {
        List<MandatoryReport> list = mandatoryReportService.selectMandatoryReportList(mandatoryReport);
        ExcelUtil<MandatoryReport> util = new ExcelUtil<MandatoryReport>(MandatoryReport.class);
        return util.exportExcel(list, "report");
    }

    /**
     * PC端导出【请填写功能名称】列表
     */
    @PostMapping("/exportPc")
    public void export1(HttpServletResponse response,MandatoryReport mandatoryReport) {
        List<MandatoryReport> list = mandatoryReportService.selectMandatoryReportList1(mandatoryReport);
        ExcelUtil<MandatoryReport> util = new ExcelUtil<MandatoryReport>(MandatoryReport.class);
        util.exportExcel(response, list, "report");
    }

    /**
     * 新增【请填写功能名称】
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存【请填写功能名称】
     */
    @PostMapping("/add")
    public AjaxResult addSave(@RequestBody MandatoryReport mandatoryReport) {
        return mandatoryReportService.insertMandatoryReport(mandatoryReport);
    }

    /**
     * 修改【请填写功能名称】
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        MandatoryReport mandatoryReport = mandatoryReportService.selectMandatoryReportById(id);
        mmap.put("mandatoryReport", mandatoryReport);
        return prefix + "/edit";
    }

    /**
     * 修改保存【请填写功能名称】
     */
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MandatoryReport mandatoryReport) {
        return toAjax(mandatoryReportService.updateMandatoryReport(mandatoryReport));
    }

    /**
     * 删除【请填写功能名称】
     */

    @PostMapping("/remove")
    public AjaxResult remove(@RequestBody Map<String, String> map) {
        return toAjax(mandatoryReportService.deleteMandatoryReportByIds(map));
    }

    /**
     * 批量修改
     */
    @PostMapping("/updateByIds")
    public AjaxResult uodateByIds(@RequestBody Map<String, String> map) {
        return toAjax(mandatoryReportService.updateTCarouselImageByIds(map));
    }

}
